<template>
	<view class="chat-item" @click="showChatBox()">
		<view class="left">
			<!-- <head-image :url="chat.headImage" :name="chat.showName" :size="90"></head-image> -->
			<image :src="chat.headImage" style="width: 80rpx; height: 80rpx; border-radius: 10rpx;" v-if="chat.headImage"></image>
			<view v-else style="width: 80rpx; height: 80rpx; font-size: 24rpx; border: 2rpx solid #ccc; text-align: center; line-height: 80rpx; border-radius: 10rpx;">群聊</view>
			<view v-if="chat.unreadCount>0" class="unread-text">{{chat.unreadCount}}</view>
		</view>
		<view class="chat-right">
			<view class="chat-name">
				<view class="chat-name-text">{{chat.showName}}</view>
				<view class="chat-time">{{$date.toTimeText(chat.lastSendTime,true)}}</view>
			</view>
			<view class="chat-content">
				<view class="chat-at-text">{{atText}}</view>
				<view class="chat-send-name" v-show="chat.sendNickName">{{chat.sendNickName+':&nbsp;'}}</view>
				<rich-text class="chat-content-text" :nodes="$emo.transform(chat.lastContent)"></rich-text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "chatItem",
		data() {
			return {}
		},
		props: {
			chat: {
				type: Object
			},
			index: {
				type: Number
			}
		},
		methods: {
			showChatBox() {
				uni.navigateTo({
					url: "/pages/chat/chat-box?chatIdx=" + this.index
				})
			}
		},
		computed: {
			atText() {
				if (this.chat.atMe) {
					return "[有人@我]"
				} else if (this.chat.atAll) {
					return "[@全体成员]"
				}
				return "";
			}
		}
	}
</script>

<style scoped lang="scss">
	.chat-item {
		// height: 100rpx;
		display: flex;
		align-items: center;
		position: relative;
		// padding: 10rpx;
		padding-top: 30rpx;
		// padding-left: 20rpx;
		align-items: center;
		background-color: white;
		white-space: nowrap;
		&:hover {
			background-color: #eeeeee;
		}
		
		::v-deep .head-image {
				// width: 80rpx;
				// height: 80rpx;
		}

		.left {
			position: relative;
			display: flex;
			// justify-content: center;
			align-items: center;
			width: 100rpx;
			height: 100rpx;
			// padding-top: 30rpx;
			padding-bottom: 30rpx;

			.unread-text {
				position: absolute;
				background-color: red;
				right: -12rpx;
				top: -12rpx;
				color: white;
				border-radius: 16rpx;
				padding: 4rpx 12rpx;
				font-size: 20rpx;
				text-align: center;
				white-space: nowrap;
			}
		}

		.chat-right {
			flex: 1;
			display: flex;
			flex-direction: column;
			// padding: 30rpx 0;
			// margin-left: 20rpx;
			padding-bottom: 30rpx;
			// padding-top: 30rpx;
			border-bottom: 2rpx solid #eee;
			text-align: left;
			overflow: hidden;

			.chat-name {
				display: flex;
				line-height: 50rpx;
				height: 50rpx;
				overflow: hidden;

				.chat-name-text {
					flex: 1;
					padding-right: 20rpx;
					font-size: 30rpx;
					// font-weight: 600;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					color: #333333;
				}

				.chat-time {
					font-size: 26rpx;
					text-align: right;
					color: #888888;
					white-space: nowrap;
					overflow: hidden;
				}
			}

			.chat-content {
				display: flex;
				align-items: center;
				line-height: 44rpx;
				.chat-at-text {
					color: #c70b0b;
					font-size: 24rpx;
				}

				.chat-send-name {
					font-size: 28rpx;
					color: #999;
				}

				.chat-content-text {
					flex: 1;
					font-size: 28rpx;
					white-space: nowrap;
					overflow: hidden !important;
					line-height: 50rpx;
					text-overflow: ellipsis;
					pointer-events: none;
					color: #999;
					::v-deep div {
						white-space: nowrap;
						overflow: hidden;
						line-height: 50rpx;
						text-overflow: ellipsis;
						img {
							width: 50rpx;
							height: 50rpx !important;
						}
					}
					
				}
			}
		}
	}
</style>